package com.itheima.reggie.common;

import lombok.Data;
import java.util.HashMap;
import java.util.Map;

/**
 * common result in server
 * @author 武帅丞
 * @date 2024/09/09
 * @param <T>
 */

@Data
public class ServerResultVO<T> {

    private Integer code; //编码：1成功，0和其它数字为失败

    private String msg; //错误信息

    private T data; //数据

    private Map map = new HashMap(); //动态数据

    public static <T> ServerResultVO<T> success(T object) {
        ServerResultVO<T> serverResultVO = new ServerResultVO<T>();
        serverResultVO.data = object;
        serverResultVO.code = 1;
        return serverResultVO;
    }

    public static <T> ServerResultVO<T> error(String msg) {
        ServerResultVO serverResultVO = new ServerResultVO();
        serverResultVO.msg = msg;
        serverResultVO.code = 0;
        return serverResultVO;
    }

    public ServerResultVO<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }

}
